package com.oms.util;


import com.oms.common.HttpAPIService;
import com.oms.common.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author zhanghailong QQ38592077
 * @Description TODO
 * @Date 2020/7/3 10:28
 */
@Component
public class TextMessageVerificationTools {
    /**
     * 用户开发key
     */
    private final String accesskey = "EjAxI0rR0YL800NA";
    /**
     * 用户开发秘钥
     */
    private final String secret = "zvILNoAjAXOJyxl2BkTDNZYR1OISJqdC";

    /**
     *
     */
    private final String apikey="iqJgb3UxX5O27vONn71uti38v2oS2nWS";

    @Autowired
    HttpAPIService httpAPIService;

    /**
     * 获取签名列表
     * @return
     * @throws Exception
     */
    public HttpResult getSign() throws Exception {
        String url = "http://api.1cloudsp.com/query/signlist";
        Map<String, Object> map = new HashMap<>();
        map.put("accesskey",accesskey);
        map.put("secret",secret);
        return httpAPIService.doPost(url, map);
    }

    /**
     * 获取模板列表
     * @return
     * @throws Exception
     */
    public HttpResult getTemplate() throws Exception {
        String url = "http://api.1cloudsp.com/query/templatelist";
        Map<String, Object> map = new HashMap<>();
        map.put("accesskey",accesskey);
        map.put("secret",secret);
        return httpAPIService.doPost(url, map);
    }

    /**
     * 发送短信
     * @param sign
     * @param templateId
     * @param mobile
     * @param content 示例：先生##9:40##快递公司##1234567（示例模板：{1}您好，您的订单于{2}已通过{3}发货，运单号{4}）
     * @return
     * @throws Exception
     */
    public HttpResult sendMessage (String sign,String templateId,String mobile,String content) throws Exception {
        String url = "http://api.tinree.com/api/v2/send";
        Map<String, Object> map = new HashMap<>();
        map.put("accesskey",accesskey);
        map.put("secret",secret);
        map.put("sign",sign);
        map.put("templateId",templateId);
        map.put("mobile",mobile);
        map.put("content", URLEncoder.encode(content, "utf-8"));
        return httpAPIService.doPost(url, map);
    }
}
